package com.party.core.service.quartz.impl;

import com.google.common.base.Strings;
import com.google.common.collect.Maps;
import com.party.common.paging.Page;
import com.party.core.dao.read.quartz.QuartzDataMapReadDao;
import com.party.core.dao.write.quartz.QuartzDataMapWriteDao;
import com.party.core.model.BaseModel;
import com.party.core.model.quartz.QuartzDataMap;
import com.party.core.service.quartz.IQuartzDataMapService;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.map.HashedMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * @Description:
 * @Author: yangshoukun
 * @Date: 2018/4/26 17:33
 */
@Service
public class QuartzDataMapService implements IQuartzDataMapService {
    @Autowired
    private QuartzDataMapReadDao quartzDataMapReadDao;

    @Autowired
    private QuartzDataMapWriteDao quartzDataMapWriteDao;

    @Override
    public String insert(QuartzDataMap quartzDataMap) {
        BaseModel.preInsert(quartzDataMap);
        boolean result = quartzDataMapWriteDao.insert(quartzDataMap);
        if (result){
            return quartzDataMap.getId();
        }
        return null;
    }

    @Override
    public boolean update(QuartzDataMap quartzDataMap) {
        return quartzDataMapWriteDao.update(quartzDataMap);
    }

    @Override
    public boolean deleteLogic(String id) {
        if (Strings.isNullOrEmpty(id)){
            return false;
        }
        return quartzDataMapWriteDao.deleteLogic(id);
    }

    @Override
    public boolean delete(String id) {
        if (Strings.isNullOrEmpty(id)){
            return false;
        }
        return quartzDataMapWriteDao.delete(id);
    }

    @Override
    public boolean batchDeleteLogic(Set<String> ids) {
        if (CollectionUtils.isEmpty(ids)){
            return false;
        }
        return quartzDataMapWriteDao.batchDeleteLogic(ids);
    }

    @Override
    public boolean batchDelete(Set<String> ids) {
        if (CollectionUtils.isEmpty(ids)){
            return false;
        }
        return quartzDataMapWriteDao.batchDelete(ids);
    }

    @Override
    public QuartzDataMap get(String id) {
        return quartzDataMapReadDao.get(id);
    }

    @Override
    public List<QuartzDataMap> listPage(QuartzDataMap quartzDataMap, Page page) {
        return quartzDataMapReadDao.listPage(quartzDataMap, page);
    }

    @Override
    public List<QuartzDataMap> list(QuartzDataMap quartzDataMap) {
        return listPage(quartzDataMap, null);
    }

    @Override
    public List<QuartzDataMap> batchList(Set<String> ids, QuartzDataMap quartzDataMap, Page page) {
        Map<String, Object> query = Maps.newHashMap();
        return quartzDataMapReadDao.batchList(ids, new HashedMap(), page);
    }

    @Override
    public QuartzDataMap findByTargetId(String targetId) {
        return quartzDataMapReadDao.findByTargetId(targetId);
    }
}
